package com.woniuxy.homepage.core.service.impl;

import com.woniuxy.homepage.core.constant.PromotionConstant;
import com.woniuxy.homepage.core.model.CarGoods;
import com.woniuxy.homepage.core.mapper.CarGoodsMapper;
import com.woniuxy.homepage.core.service.CarGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@Service
public class CarGoodsServiceImpl extends ServiceImpl<CarGoodsMapper, CarGoods> implements CarGoodsService {

    @Resource
    private CarGoodsMapper carGoodsMapper;

    @Override
    public List<CarGoods> selectAllTyre() {
        List<CarGoods> list = this.carGoodsMapper.selectAllTyre();
        return list;
    }

    @Override
    public List<CarGoods> selectAllSound() {
        List<CarGoods> list = this.carGoodsMapper.selectAllSound();
        return list;
    }

    @Override
    public List<CarGoods> selectBoutique() {
        List<CarGoods> list = this.carGoodsMapper.selectBoutique();
        return list;
    }

    @Override
    public List<CarGoods> selectGoodsManage() {
        List<CarGoods> list = this.carGoodsMapper.selectGoodsManage();
        for (CarGoods goods :list) {
            if (goods.getRecommend() == 0){
                goods.setRecommendChinese("未推荐");
            }
            if (goods.getRecommend() == 1){
                goods.setRecommendChinese("推荐");
            }
        }
        return list;
    }

    @Override
    public int recommend(Integer id) {
        CarGoods goods = this.carGoodsMapper.selectByGoodsId(id);
        goods.setRecommend(PromotionConstant.GOODS_RECOMMEND);
        int i = this.carGoodsMapper.updateById(goods);
        return i;
    }

    @Override
    public int disRecommned(Integer id) {
        CarGoods goods = this.carGoodsMapper.selectByGoodsId(id);
        goods.setRecommend(PromotionConstant.DIS_GOODS_RECOMMEND);
        int i = this.carGoodsMapper.updateById(goods);
        return i;
    }

    @Override
    public List<CarGoods> selectGoods(CarGoods carGoods) {
        List<CarGoods> list = this.carGoodsMapper.selectGoods(carGoods);
        for (CarGoods goods :list) {
            if (goods.getRecommend() == 0){
                goods.setRecommendChinese("未推荐");
            }
            if (goods.getRecommend() == 1){
                goods.setRecommendChinese("推荐");
            }
        }
        return list;
    }

    @Override
    public int insertGoods(CarGoods carGoods) {
        carGoods.setImg("../../../static/"+carGoods.getImg());
        int i = this.carGoodsMapper.insert(carGoods);
        return i;
    }

    @Override
    public int updateGoods(CarGoods carGoods) {
        int i = this.carGoodsMapper.updateById(carGoods);
        return i;
    }

    @Override
    public int deleteGoods(Integer id) {
        int i = this.carGoodsMapper.deleteById(id);
        return i;
    }
}
